package reflect;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Author: DengJia
 * @Date: 2021/12/1 9:09
 * @Description: 通过JDK实现动态代理
 */

public class DebugInvocationHandler implements InvocationHandler {

    /* 代理中的真是对象 */
    private final Object target;

    public DebugInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("调用方法之前，" + method.getName());
        Object result = method.invoke(target, args);
        System.out.println("调用方法之后，" + method.getName());
        return result;
    }
}
